package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 数据字典-订单状态
 * @author wujian
 * @version v1.0
 * @date 2021/01/04 22:00
 * @since v1.0
 */
@Getter
public enum OrderStatusEnum {


    //待订单审核
    PENDING_ORDER_REVIEW("1","enum.orderStatus.name.pending_order_review","PendingOrderReview"),
    //待财务审核
    PENDING_FINANCIAL_REVIEW("2","enum.orderStatus.name.pending_financial_review","PendingFinancialReview"),
    //待发货
    DELIVERED("3","enum.orderStatus.name.delivered","delivered"),
    //待收货
    RECEIVED("4","enum.orderStatus.name.received","received"),
    //已完成
    COMPLETED("5","enum.orderStatus.name.completed","completed"),
    //已作废
    ABOLISHED("6","enum.orderStatus.name.abolished","abolished"),
    //已关闭
    CLOSED("7","enum.orderStatus.name.closed","closed")
    ;
    private String code;
    private String name;
    private String attr;


    OrderStatusEnum(String code, String name, String attr) {
        this.code = code;
        this.name = name;
        this.attr = attr;
    }
    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public static List<String> getApproval() {
        return Arrays.asList(PENDING_ORDER_REVIEW.code, RECEIVED.code);
    }

    public static List<String> getCode4Statistics() {
        return Arrays.asList(DELIVERED.code, RECEIVED.code, COMPLETED.code, CLOSED.code);
    }

    public static List<String> getNotWaitSettlement() {
        return Arrays.asList(ABOLISHED.code, CLOSED.code);
    }

    public static OrderStatusEnum getByCode(String code) {
        for (OrderStatusEnum orderStatusEnum : OrderStatusEnum.values()) {
            if (Objects.equals(orderStatusEnum.getCode(), code)) {
                return orderStatusEnum;
            }
        }
        return OrderStatusEnum.PENDING_ORDER_REVIEW;
    }

    public static List<OrderStatusEnum> getList(){
        List<OrderStatusEnum> enumList = new ArrayList<>(OrderStatusEnum.values().length);
        Collections.addAll(enumList, values());
        return enumList;
    }

    public static Map<String, String> orderStatusMap(){
        Map<String, String> orderStatusMap = new HashMap<>();
        for (OrderStatusEnum value : values()) {
            orderStatusMap.put(value.getCode(), I18nMessageUtil.getMessage(value.getName()));
        }
        return orderStatusMap;
    }

}
